package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.*;
import yxy.cherry.battle.module.record.stream.RecordStream42TriggerSkill;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 偷取属性
 * @date 2022/3/1 9:21
 **/
@SkillType(Type = AffixFactory.SkillTypeEnum.偷取属性)
public class Affix28StealAdd extends Skill {
    public Affix28StealAdd(Fighter actor, skill skilldata, int probability, int[] params) {
        super(actor, skilldata, probability, params);
    }

    private int getBuffID1() {return getParam(0);}
    private int getBuffID2() {return getParam(1);}
    private int getBuffID3() {return getParam(2);}
    private int getBuffID4() {return getParam(3);}

    @Override
    public boolean exec(Fighter source, Fighter target) {
        AffixContext.AffixAction affixAction = getAffixAction();
        getRecord().stream(new RecordStream42TriggerSkill(getActor(),503)).record();
        getRecord().stream(new RecordStream_SKL(getActor(),getSkillId())).record();

        skill skilldata1 = DataCenter.getData(getBuffID1(), skill.class);
        Buff buff1 = AffixFactory.getInstance().getBuff(AffixFactory.BuffTypeEnum.valueOf(skilldata1.getBufftype()), source, source, skilldata1, getSelfParams(skilldata1));
        buff1.append(source);
        buff1.active();

        skill skilldata2 = DataCenter.getData(getBuffID2(), skill.class);
        Buff buff2 = AffixFactory.getInstance().getBuff(AffixFactory.BuffTypeEnum.valueOf(skilldata2.getBufftype()), source, target, skilldata2, getSelfParams(skilldata2));
        buff2.append(target);
        buff2.active();

        skill skilldata3 = DataCenter.getData(getBuffID3(), skill.class);
        Buff buff3 = null;
        if (skilldata3 != null) {
            buff3 = AffixFactory.getInstance().getBuff(AffixFactory.BuffTypeEnum.valueOf(skilldata3.getBufftype()), source, target, skilldata3, getSelfParams(skilldata3));
            buff3.append(source);
            buff3.active();
        }

        skill skilldata4 = DataCenter.getData(getBuffID4(), skill.class);
        Buff buff4 = null;
        if (skilldata4 != null) {
            buff4 = AffixFactory.getInstance().getBuff(AffixFactory.BuffTypeEnum.valueOf(skilldata4.getBufftype()), target, target, skilldata4, getSelfParams(skilldata4));
            buff4.append(target);
            buff4.active();
        }

        Battle.battleLogger(6,"偷取属性：施法者"+source.getName()+"目标："+target.getName());
        return true;
    }

    private int[] getSelfParams(skill skilldata){
        int[] params = new int[skilldata.getParam().length];
        for (int i = 0; i < params.length; i++) {
            params[i] = skilldata.getParam()[i];
        }
        return params;
    }
}
